﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EBA.MQ
{
    /// <summary>
    /// 消息中介路由表
    /// </summary>
    public class BrokerRouteTable
    {
        /// <summary>
        /// 路由列表
        /// </summary>
        public IEnumerable<BrokerRoute> Routes
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        /// <summary>
        /// 已经建立的通讯通道列表
        /// </summary>
        public IEnumerable<IChannel> Channels
        {
            get
            {
                throw new NotImplementedException();
            }
        }

        /// <summary>
        /// 获取达到目标队列的最短路径的第一个路由节点。
        /// </summary>
        /// <param name="source"></param>
        /// <param name="queue"></param>
        /// <returns></returns>
        public BrokerRoute GetNextRoute(BrokerRoute source, QueueMetadata queue)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 获取目标队列所在的消息中介的路由列表。
        /// </summary>
        /// <param name="queue"></param>
        /// <returns></returns>
        public IEnumerable<BrokerRoute> GetRoutes(QueueMetadata queue)
        {
            if (string.IsNullOrWhiteSpace(queue.QueueId))
            {
                return this.Routes.Where(i => i.Queues.Any(q => q.QueueName == queue.QueueName));
            }
            else
            {
                return this.Routes.Where(i => i.Queues.Any(q => q.QueueId == queue.QueueId && q.QueueName == queue.QueueName));
            }
        }

        /// <summary>
        /// 建立两个路由间的通讯通道
        /// </summary>
        public IChannel Connect(BrokerRoute source, BrokerRoute destination)
        {
            throw new NotImplementedException();

        }

        void ChannelDataReceived(IBinding sourc, IBinding destination, byte[] buffer)
        {
            //throw new NotImplementedException();
        }
    }
}
